<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('loan_application', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->default(0)->comment("用户id");
            $table->char('org_root',3)->nullable()->comment('顶级机构');
            $table->char('org_code',11)->nullable()->comment('所属机构');
            $table->unsignedSmallInteger('status')->default(0)->comment("状态");
            $table->unsignedTinyInteger('is_allocated')->default(0)->comment("是否已经分派");
            $table->unsignedBigInteger('new_appid')->default(0)->comment("超管收回后新的ID");
            $table->char('mobile', 11)->comment("用户联系电话");
            $table->char('name', 40)->comment("称呼");
            $table->integer('amount_start')->comment("期望贷款额度最小值, 单位元");
            $table->integer('amount_end')->comment("期望贷款额度最大值, 单位元, 如果超过1万亿，则表示无上限");
            $table->unsignedSmallInteger('need_home_service')->default(0)->comment("是否需要上门服务");
            $table->string('province', 40)->comment("省");
            $table->string('city', 40)->comment("市");
            $table->string('district', 40)->comment("区/县");
            $table->string('addr', 40)->comment("详细地址");
            $table->char('category', 20)->comment("类别: 企业税贷/房抵贷/企业票贷/车抵贷/信用贷/公积金贷等");
            $table->timestamps();
        });
        DB::statement("ALTER TABLE `loan_application` comment '贷款申请物料'");

        Schema::create('loan_application_log', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('loan_id')->default(0)->comment("申请物料id");
            $table->unsignedBigInteger('user_id')->comment("用户id");
            $table->char('org_root',3)->nullable()->comment('顶级机构');
            $table->char('org_code',11)->nullable()->comment('所属机构');
            $table->text('comment')->comment("备注日志");
            $table->timestamps();
        });
        DB::statement("ALTER TABLE `loan_application_log` comment '贷款申请物料操作日志'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('loan_application');
        Schema::dropIfExists('loan_application_log');
    }
};
